﻿@{
    Layout = "~/Views/Shared/_Form.cshtml";
}
@using Raffles.OA.Data;
@using Raffles.OA.Utility;
<link href="~/Content/plugin/zTree/v3/css/metroStyle/metroStyle.min.css" rel="stylesheet" />

<link href="~/Content/plugin/jquery.rating-stars/jquery.rating-stars.css" rel="stylesheet" />
<form id="form" class="form-horizontal m" role="form">
    <div class="form-group">
        <label class="col-sm-3 control-label ">类目<span class="text-red"> *</span></label>
        <div class="col-sm-9">
            <select id="code" col="Code" class="form-control" disabled>
            </select>
        </div>
    </div>
    <div class="form-group level" style="display:none">
        <label class="col-sm-3 control-label ">分类<span class="text-red"> &nbsp;</span></label>
        <div class="col-sm-9">
            <div id="parentId" col="ParentId">
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label ">名称<span class="text-red"> *</span></label>
        <div class="col-sm-9">
            <input id="name" name="Name" col="Name" type="text" class="form-control required " placeholder="请输入名称" />
        </div>
    </div>

    <div class="form-group star" style="display:none">
        <label class="col-sm-3 control-label ">酒店星级<span class="text-red"> *</span></label>
        <div class="col-sm-9">
            <div class="rating-stars block">
                <input type="hidden" id="Star" col="Star" class="rating-value">
                <div class="rating-stars-container text-left">
                    <div class="rating-star">
                        <i class="fa fa-star"></i>
                    </div>
                    <div class="rating-star">
                        <i class="fa fa-star"></i>
                    </div>
                    <div class="rating-star">
                        <i class="fa fa-star"></i>
                    </div>
                    <div class="rating-star">
                        <i class="fa fa-star"></i>
                    </div>
                    <div class="rating-star">
                        <i class="fa fa-star"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="form-group price">
        <label class="col-sm-3 control-label ">基础单价<span class="text-red"> *</span></label>
        <div class="col-sm-9">
            <input id="price" name="Price" col="Price" type="number" class="form-control required " placeholder="请输入基础单价" />
        </div>
    </div>
    <div class="form-group isDefault">
        <label class="col-sm-3 control-label ">默认带出<span class="text-red"> *</span></label> 
        <div class="col-xs-9" id="isDefault" col="IsDefault">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label ">备注说明<span class="text-red"> &nbsp;</span></label>
        <div class="col-sm-9">
            <textarea id="remark" name="Remark" col="Remark" type="text" class="form-control" placeholder="请输入备注说明"></textarea>
        </div>
    </div>
</form>
<script src="~/Content/plugin/zTree/v3/js/ztree.min.js"></script>
<script src="~/Content/plugin/jquery.rating-stars/jquery.rating-stars.min.js"></script>
<script type="text/javascript">
    var id = frame.request("id");
    var code = frame.request("code");
    $(function () {
        $("#code").frameSelect({
            data: frame.getJson(@Html.Raw(typeof(QuotationItemEnum).EnumToCodeDictionaryString())),
            default: code
        });
        $("#isDefault").frameRadioBox({
            data: frame.getJson(@Html.Raw(typeof(YesOrNoEnum).EnumToDictionaryString())),
            default: @((int)YesOrNoEnum.No)
        });
        if (code == "@QuotationItemEnum.Hotel.ToString()") {
            $('.star').show();
            $(".rating-stars").ratingStars();
        }
        else if (code == "@QuotationItemEnum.Destination.ToString()") {
            $('.price').hide();
            $('.isDefault').hide();
            $('.level').show();
            $('#parentId').frameComboBoxTree({
                url: '@Url.Content("/Sale/BaseInfo/GetDestinationTreeSelect")',
                expandLevel: -1

            });
        } 
        getForm();
    });

    function getForm() {
        if (!!id) {
            frame.ajax({
                url: '@Url.Content("/Sale/BaseInfo/SetBaseForm")' + '?id=' + id + "&code=" + code,
                type: 'get',
                success: function (obj) {
                    if (obj.success) {
                        obj.data.Code = code;
                        $('#form').setWebControls(obj.data);
                        if (code == "@QuotationItemEnum.Hotel.ToString()") {
                            $(".rating-stars").ratingStars();
                        }
                    }
                }
            });
        }
        else {
            var defaultData = { Code: code };
            $('#form').setWebControls(defaultData);
        }
    }

    function saveForm(index) {
        if ($('#form').validate().form()) {
            var postData = $('#form').getWebControls({ Id: id });
            frame.ajax({
                url: '@Url.Content("/Sale/BaseInfo/SaveBaseForm")',
                type: 'post',
                data: postData,
                success: function (obj) {
                    if (obj.success) {
                        frame.msgSuccess(obj.message);
                        parent.PageUI.searchGrid(code);
                        parent.layer.close(index);
                    }
                    else {
                        frame.msgError(obj.message);
                    }
                }
            });
        }
    }
</script>

